﻿// SettingDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "SettingDlg.h"
#include "afxdialogex.h"


// CSettingDlg 对话框

IMPLEMENT_DYNAMIC(CSettingDlg, CDialogEx)

CSettingDlg::CSettingDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_SETTING, pParent)
	, nPosX0(0)
	, nPosX1(1)
	, nPosX2(2)
	, nPosX3(3)
	, nPosX4(4)
	, nPosX5(5)
	, nPosX6(6)
	, nPosY0(0)
	, nPosY1(1)
	, nPosY2(2)
	, nPosY3(3)
	, nPosY4(4)
	, nPosY5(5)
	, nPosY6(6)
	, nPosZ0(0)
	, nPosZ1(1)
	, nPosZ2(2)
	, nPosZ3(3)
	, nPosZ4(4)
	, nPosZ5(5)
	, nPosZ6(6)
	, bFlag0(FALSE)
	, bFlag1(FALSE)
	, bFlag2(FALSE)
	, bFlag3(FALSE)
	, bUseUpFlag(FALSE)
	, nPitouCount(0)
	, OpenWeiyi(FALSE)
	, m_dSpecUp(0)
	, m_dSpecDown(0)
	, bPassYamahaFlag(FALSE)
	, m_bSecondCode(FALSE)
	, CheckSN1(_T(""))
	, CheckFlag1(FALSE)
	, CheckSN2(_T(""))
	, CheckFlag2(FALSE)
	, AlarmFlag(FALSE)
	, nPosX7(0)
	, nPosX8(0)
	, nPosY7(0)
	, nPosY8(0)
	, nPosZ7(0)
	, nPosZ8(0)
	, bFlag4(0)
	, bFlag5(0)
	, Pass30Flag(FALSE)
	, OpenAutoFlag_10(FALSE)
{

}

CSettingDlg::~CSettingDlg()
{
}

void CSettingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_POS_X1, nPosX0);
	DDX_Text(pDX, IDC_POS_X2, nPosX1);
	DDX_Text(pDX, IDC_POS_X3, nPosX2);
	DDX_Text(pDX, IDC_POS_X4, nPosX3);
	DDX_Text(pDX, IDC_POS_X5, nPosX4);
	DDX_Text(pDX, IDC_POS_X6, nPosX5);
	DDX_Text(pDX, IDC_POS_X7, nPosX6);
	DDX_Text(pDX, IDC_POS_Y1, nPosY0);
	DDX_Text(pDX, IDC_POS_Y2, nPosY1);
	DDX_Text(pDX, IDC_POS_Y3, nPosY2);
	DDX_Text(pDX, IDC_POS_Y4, nPosY3);
	DDX_Text(pDX, IDC_POS_Y5, nPosY4);
	DDX_Text(pDX, IDC_POS_Y6, nPosY5);
	DDX_Text(pDX, IDC_POS_Y7, nPosY6);
	DDX_Text(pDX, IDC_POS_Z1, nPosZ0);
	DDX_Text(pDX, IDC_POS_Z2, nPosZ1);
	DDX_Text(pDX, IDC_POS_Z3, nPosZ2);
	DDX_Text(pDX, IDC_POS_Z4, nPosZ3);
	DDX_Text(pDX, IDC_POS_Z5, nPosZ4);
	DDX_Text(pDX, IDC_POS_Z6, nPosZ5);
	DDX_Text(pDX, IDC_POS_Z7, nPosZ6);
	DDX_Check(pDX, IDC_CHECK_FLAG1, bFlag0);
	DDX_Check(pDX, IDC_CHECK_FLAG2, bFlag1);
	DDX_Check(pDX, IDC_CHECK_FLAG3, bFlag2);
	DDX_Check(pDX, IDC_CHECK_FLAG4, bFlag3);
	DDX_Check(pDX, IDC_CHECK_FLAG5, bUseUpFlag);
	DDX_Text(pDX, IDC_CNT_MAX, nPitouCount);
	DDX_Check(pDX, IDC_CHECK_FLAG6, OpenWeiyi);
	DDX_Text(pDX, IDC_CNT_MAX2, m_dSpecUp);
	DDX_Text(pDX, IDC_CNT_MAX3, m_dSpecDown);
	DDX_Check(pDX, IDC_CHECK_FLAG7, bPassYamahaFlag);
	DDX_Check(pDX, IDC_CHECK_FLAG8, m_bSecondCode);
	DDX_Text(pDX, IDC_EDIT_CHECKSN1, CheckSN1);
	DDX_Check(pDX, IDC_CHECK_SN1, CheckFlag1);
	DDX_Text(pDX, IDC_EDIT_CHECKSN2, CheckSN2);
	DDX_Check(pDX, IDC_CHECK_SN2, CheckFlag2);
	DDX_Control(pDX, IDC_COMBO_YAMAHA, YamahaMode);
	DDX_Check(pDX, IDC_CHECK_FLAG9, AlarmFlag);
	DDX_Text(pDX, IDC_POS_X8, nPosX7);
	DDX_Text(pDX, IDC_POS_X9, nPosX8);
	DDX_Text(pDX, IDC_POS_Y8, nPosY7);
	DDX_Text(pDX, IDC_POS_Y9, nPosY8);
	DDX_Text(pDX, IDC_POS_Z8, nPosZ7);
	DDX_Text(pDX, IDC_POS_Z9, nPosZ8);
	DDX_Check(pDX, IDC_CHECK_FLAG10, bFlag4);
	DDX_Check(pDX, IDC_CHECK_FLAG11, bFlag5);
	DDX_Check(pDX, IDC_CHECK_FLAG12, Pass30Flag);
	DDX_Check(pDX, IDC_CHECK_FLAG13, OpenAutoFlag_10);
}


BEGIN_MESSAGE_MAP(CSettingDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CSettingDlg::OnBnClickedButtonSave)
END_MESSAGE_MAP()


// CSettingDlg 消息处理程序


BOOL CSettingDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	ReadConfigIni();

	YamahaMode.ResetContent();
	YamahaMode.AddString(L"0: FY11/NL3B");
	YamahaMode.AddString(L"1: CC11");
	YamahaMode.SetCurSel(gSystemMgr.YamahaMode);

	return TRUE;
}


void CSettingDlg::OnCancel()
{
	// TODO: 在此添加专用代码和/或调用基类

	CDialogEx::OnCancel();
}

void CSettingDlg::ReadConfigIni()
{
	nPosX0 = gSystemMgr.m_nPosX[0];
	nPosX1 = gSystemMgr.m_nPosX[1];
	nPosX2 = gSystemMgr.m_nPosX[2];
	nPosX3 = gSystemMgr.m_nPosX[3];
	nPosX4 = gSystemMgr.m_nPosX[4];
	nPosX5 = gSystemMgr.m_nPosX[5];
	nPosX6 = gSystemMgr.m_nPosX[6];
	nPosY0 = gSystemMgr.m_nPosY[0];
	nPosY1 = gSystemMgr.m_nPosY[1];
	nPosY2 = gSystemMgr.m_nPosY[2];
	nPosY3 = gSystemMgr.m_nPosY[3];
	nPosY4 = gSystemMgr.m_nPosY[4];
	nPosY5 = gSystemMgr.m_nPosY[5];
	nPosY6 = gSystemMgr.m_nPosY[6];
	nPosZ0 = gSystemMgr.m_nPosZ[0];
	nPosZ1 = gSystemMgr.m_nPosZ[1];
	nPosZ2 = gSystemMgr.m_nPosZ[2];
	nPosZ3 = gSystemMgr.m_nPosZ[3];
	nPosZ4 = gSystemMgr.m_nPosZ[4];
	nPosZ5 = gSystemMgr.m_nPosZ[5];
	nPosZ6 = gSystemMgr.m_nPosZ[6];
	bFlag0 = gSystemMgr.m_nLockFlag[0];
	bFlag1 = gSystemMgr.m_nLockFlag[1];
	bFlag2 = gSystemMgr.m_nLockFlag[2];
	bFlag3 = gSystemMgr.m_nLockFlag[3];

	nPosX7 = gSystemMgr.m_nPosX[7];
	nPosX8 = gSystemMgr.m_nPosX[8];
	nPosY7 = gSystemMgr.m_nPosY[7];
	nPosY8 = gSystemMgr.m_nPosY[8];
	nPosZ7 = gSystemMgr.m_nPosZ[7];
	nPosZ8 = gSystemMgr.m_nPosZ[8];
	bFlag4 = gSystemMgr.m_nLockFlag[4];
	bFlag5 = gSystemMgr.m_nLockFlag[5];

	bUseUpFlag = gSystemMgr.m_bUseUpFlag;
	bPassYamahaFlag = gSystemMgr.m_bPassYamahaFlag;

	nPitouCount = gSystemMgr.m_nPitouMax;

	OpenWeiyi = gSystemMgr.m_nOpenWeiyi;
	m_dSpecUp = gSystemMgr.m_dSpecUp;
	m_dSpecDown = gSystemMgr.m_dSpecDown;

	m_bSecondCode = gSystemMgr.m_bSecondCode;

	CheckSN1 = gSystemMgr.CheckSN1;
	CheckFlag1 = gSystemMgr.CheckFlag1;
	CheckSN2 = gSystemMgr.CheckSN2;
	CheckFlag2 = gSystemMgr.CheckFlag2;
	AlarmFlag = gSystemMgr.AlarmFlag;

	Pass30Flag = gSystemMgr.Pass30Flag;

	OpenAutoFlag_10 = gSystemMgr.OpenAutoFlag_10;

	UpdateData(FALSE);
}

void CSettingDlg::SaveEditValueToConfig()
{
	UpdateData(TRUE);

	gSystemMgr.m_nPosX[0] = nPosX0;
	gSystemMgr.m_nPosX[1] = nPosX1;
	gSystemMgr.m_nPosX[2] = nPosX2;
	gSystemMgr.m_nPosX[3] = nPosX3;
	gSystemMgr.m_nPosX[4] = nPosX4;
	gSystemMgr.m_nPosX[5] = nPosX5;
	gSystemMgr.m_nPosX[6] = nPosX6;
	gSystemMgr.m_nPosY[0] = nPosY0;
	gSystemMgr.m_nPosY[1] = nPosY1;
	gSystemMgr.m_nPosY[2] = nPosY2;
	gSystemMgr.m_nPosY[3] = nPosY3;
	gSystemMgr.m_nPosY[4] = nPosY4;
	gSystemMgr.m_nPosY[5] = nPosY5;
	gSystemMgr.m_nPosY[6] = nPosY6;
	gSystemMgr.m_nPosZ[0] = nPosZ0;
	gSystemMgr.m_nPosZ[1] = nPosZ1;
	gSystemMgr.m_nPosZ[2] = nPosZ2;
	gSystemMgr.m_nPosZ[3] = nPosZ3;
	gSystemMgr.m_nPosZ[4] = nPosZ4;
	gSystemMgr.m_nPosZ[5] = nPosZ5;
	gSystemMgr.m_nPosZ[6] = nPosZ6;
	gSystemMgr.m_nLockFlag[0] = bFlag0;
	gSystemMgr.m_nLockFlag[1] = bFlag1;
	gSystemMgr.m_nLockFlag[2] = bFlag2;
	gSystemMgr.m_nLockFlag[3] = bFlag3;

	gSystemMgr.m_nPosX[7] = nPosX7;
	gSystemMgr.m_nPosX[8] = nPosX8;
	gSystemMgr.m_nPosY[7] = nPosY7;
	gSystemMgr.m_nPosY[8] = nPosY8;
	gSystemMgr.m_nPosZ[7] = nPosZ7;
	gSystemMgr.m_nPosZ[8] = nPosZ8;
	gSystemMgr.m_nLockFlag[4] = bFlag4;
	gSystemMgr.m_nLockFlag[5] = bFlag5;

	gSystemMgr.m_bUseUpFlag = bUseUpFlag;
	gSystemMgr.m_bPassYamahaFlag = bPassYamahaFlag;

	gSystemMgr.m_nPitouMax = nPitouCount;

	gSystemMgr.m_nOpenWeiyi = OpenWeiyi;
	gSystemMgr.m_dSpecUp = m_dSpecUp;
	gSystemMgr.m_dSpecDown = m_dSpecDown;

	gSystemMgr.m_bSecondCode = m_bSecondCode;

	gSystemMgr.CheckSN1 = CheckSN1;
	gSystemMgr.CheckFlag1 = CheckFlag1;
	gSystemMgr.CheckSN2 = CheckSN2;
	gSystemMgr.CheckFlag2 = CheckFlag2;
	gSystemMgr.YamahaMode = YamahaMode.GetCurSel();

	gSystemMgr.AlarmFlag = AlarmFlag;

	gSystemMgr.Pass30Flag = Pass30Flag;

	gSystemMgr.OpenAutoFlag_10 = OpenAutoFlag_10;

	CString cstr;
	cstr.Format(L"%d", gSystemMgr.OpenAutoFlag_10); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"OpenAutoFlag_10", cstr);

	cstr.Format(L"%d", gSystemMgr.Pass30Flag); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"Pass30Flag", cstr);

	cstr.Format(L"%d", gSystemMgr.YamahaMode); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"YamahaMode", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nPosX[0]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosX[1]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosX[2]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosX[3]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosX[4]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[4]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosX[5]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[5]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosX[6]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[6]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosX[7]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[7]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosX[8]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosX[8]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosY[0]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosY[1]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosY[2]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosY[3]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosY[4]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[4]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosY[5]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[5]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosY[6]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[6]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosY[7]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[7]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosY[8]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosY[8]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosZ[0]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosZ[1]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosZ[2]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosZ[3]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosZ[4]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[4]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosZ[5]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[5]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosZ[6]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[6]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosZ[7]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[7]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPosZ[8]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPosZ[8]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nLockFlag[0]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[0]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nLockFlag[1]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[1]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nLockFlag[2]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[2]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nLockFlag[3]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[3]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nLockFlag[4]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[4]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nLockFlag[5]); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nLockFlag[5]", cstr);
	cstr.Format(L"%d", gSystemMgr.m_bUseUpFlag); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_bUseUpFlag", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nPitouMax); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nPitouMax", cstr);

	cstr.Format(L"%d", gSystemMgr.m_nOpenWeiyi); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_nOpenWeiyi", cstr);
	cstr.Format(L"%.3f", gSystemMgr.m_dSpecUp); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_dSpecUp", cstr);
	cstr.Format(L"%.3f", gSystemMgr.m_dSpecDown); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_dSpecDown", cstr);
	cstr.Format(L"%d", gSystemMgr.m_bPassYamahaFlag); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_bPassYamahaFlag", cstr);

	cstr.Format(L"%d", gSystemMgr.m_bSecondCode); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"m_bSecondCode", cstr);

	gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"CheckSN1", gSystemMgr.CheckSN1);
	cstr.Format(L"%d", gSystemMgr.CheckFlag1); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"CheckFlag1", cstr);
	gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"CheckSN2", gSystemMgr.CheckSN2);
	cstr.Format(L"%d", gSystemMgr.CheckFlag2); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"CheckFlag2", cstr);

	cstr.Format(L"%d", gSystemMgr.AlarmFlag); gSystemMgr.m_cPosConfigIni.SaveConfigIni(L"PosConfig", L"AlarmFlag", cstr);
}

void CSettingDlg::OnBnClickedButtonSave()
{
	SaveEditValueToConfig();
}
